using AjeeleeCms.Core.Common;
using AjeeleeCms.Web.Plugin.Link.BLL;
using AjeeleeCms.Web.Plugin.Link.Model;
using System;
using System.Text;
using System.Web;
using System.Web.SessionState;
namespace AjeeleeCms.Web.Plugin.Link
{
	public class ajax : IHttpHandler, IRequiresSessionState
	{
		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
		public void ProcessRequest(HttpContext context)
		{
			string text = context.Request.Params["action"];
			string text2 = text;
			if (text2 != null)
			{
				if (text2 == "add")
				{
					this.link_add(context);
				}
			}
		}
		private void link_add(HttpContext context)
		{
			StringBuilder stringBuilder = new StringBuilder();
			AjeeleeCms.Web.Plugin.Link.BLL.link link = new AjeeleeCms.Web.Plugin.Link.BLL.link();
			AjeeleeCms.Web.Plugin.Link.Model.link link2 = new AjeeleeCms.Web.Plugin.Link.Model.link();
			string formString = DTRequest.GetFormString("txtCode");
			string formString2 = DTRequest.GetFormString("txtTitle");
			string formString3 = DTRequest.GetFormString("txtUserName");
			string formString4 = DTRequest.GetFormString("txtUserTel");
			string formString5 = DTRequest.GetFormString("txtEmail");
			string formString6 = DTRequest.GetFormString("txtSiteUrl");
			string formString7 = DTRequest.GetFormString("txtImgUrl");
			if (string.IsNullOrEmpty(formString))
			{
				context.Response.Write("{msg:0, msgbox:\"对不起，请输入验证码！\"}");
			}
			else
			{
				if (context.Session["dt_session_code"] == null)
				{
					context.Response.Write("{msg:0, msgbox:\"对不起，系统找不到生成的验证码！\"}");
				}
				else
				{
					if (formString.ToLower() != context.Session["dt_session_code"].ToString().ToLower())
					{
						context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致！\"}");
					}
					else
					{
						if (string.IsNullOrEmpty(formString2))
						{
							context.Response.Write("{msg: 0, msgbox: \"对不起，请输入网站标题！\"}");
						}
						else
						{
							if (string.IsNullOrEmpty(formString6))
							{
								context.Response.Write("{msg: 0, msgbox: \"对不起，请输入网站网址！\"}");
							}
							else
							{
								link2.title = formString2;
								link2.is_lock = 1;
								link2.is_red = 0;
								link2.user_name = formString3;
								link2.user_tel = formString4;
								link2.email = formString5;
								link2.site_url = formString6;
								link2.img_url = formString7;
								link2.is_image = 1;
								if (string.IsNullOrEmpty(link2.img_url))
								{
									link2.is_image = 0;
								}
								if (link.Add(link2) > 0)
								{
									context.Response.Write("{msg: 1, msgbox: \"恭喜您，提交成功啦！\"}");
								}
								else
								{
									context.Response.Write("{msg: 0, msgbox: \"对不起，保存过程中发生错误！\"}");
								}
							}
						}
					}
				}
			}
		}
	}
}
